From cb5985adb8c977e7bc8af991bcf327974c4936f8 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Fri, 13 Feb 2009 10:56:01 +0900 Subject: [PATCH] [IA64] MCA: Avoid calling xmcalloc from interrupt handler This patch fixes to avoid calling xmalloc() from the interrupt handler. Calling xmalloc() with interrupt disabled triggers the following BUG_ON(). > (XEN) Xen BUG at xmalloc_tlsf.c:548 Signed-off-by: Kazuhiro Suzuki --- xen/arch/ia64/linux-xen/mca.c | 15 ++++++++++++--- xen/arch/ia64/xen/fw_emul.c | 13 ++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/xen/arch/ia64/linux-xen/mca.c b/xen/arch/ia64/linux-xen/mca.c index 3abef0bf31..84bd4b8914 100644 --- a/xen/arch/ia64/linux-xen/mca.c +++ b/xen/arch/ia64/linux-xen/mca.c @@ -210,6 +210,7 @@ static ia64_state_log_t ia64_state_log[IA64_MAX_LOG_TYPES]; #define IA64_LOG_COUNT(it) ia64_state_log[it].isl_count #ifdef XEN +sal_queue_entry_t sal_entry[NR_CPUS][IA64_MAX_LOG_TYPES]; struct list_head *sal_queue, sal_log_queues[IA64_MAX_LOG_TYPES]; sal_log_record_header_t *sal_record; DEFINE_SPINLOCK(sal_queue_lock); @@ -358,6 +359,7 @@ ia64_log_queue(int sal_info_type, int virq) if (total_len) { int queue_type; + int cpuid = smp_processor_id(); spin_lock_irqsave(&sal_queue_lock, flags); @@ -366,15 +368,22 @@ ia64_log_queue(int sal_info_type, int virq) else queue_type = sal_info_type; - e = xmalloc(sal_queue_entry_t); - BUG_ON(e == NULL); - e->cpuid = smp_processor_id(); + /* Skip if sal_entry is already listed in sal_queue */ + list_for_each_entry(e, &sal_queue[queue_type], list) { + if (e == &sal_entry[cpuid][queue_type]) + goto found; + } + e = &sal_entry[cpuid][queue_type]; + memset(e, 0, sizeof(sal_queue_entry_t)); + e->cpuid = cpuid; e->sal_info_type = sal_info_type; e->vector = IA64_CMC_VECTOR; e->virq = virq; e->length = total_len; list_add_tail(&e->list, &sal_queue[queue_type]); + + found: spin_unlock_irqrestore(&sal_queue_lock, flags); IA64_LOG_INDEX_INC(sal_info_type); diff --git a/xen/arch/ia64/xen/fw_emul.c b/xen/arch/ia64/xen/fw_emul.c index ca878b362b..2c9235a38c 100644 --- a/xen/arch/ia64/xen/fw_emul.c +++ b/xen/arch/ia64/xen/fw_emul.c @@ -95,7 +95,7 @@ void get_state_info_on(void *data) { rec_name[arg->type], smp_processor_id(), arg->ret); if (arg->corrected) { sal_record->severity = sal_log_severity_corrected; - IA64_SAL_DEBUG("%s: IA64_SAL_CLEAR_STATE_INFO(SAL_INFO_TYPE_MCA)" + IA64_SAL_DEBUG("%s: IA64_SAL_GET_STATE_INFO(SAL_INFO_TYPE_MCA)" " force\n", __FUNCTION__); } if (arg->ret > 0) { @@ -293,9 +293,7 @@ sal_emulator (long index, unsigned long in1, unsigned long in2, } r9 = arg.ret; status = arg.status; - if (r9 == 0) { - xfree(e); - } else { + if (r9 != 0) { /* Re-add the entry to sal_queue */ spin_lock_irqsave(&sal_queue_lock, flags); list_add(&e->list, &sal_queue[in1]); @@ -359,7 +357,12 @@ sal_emulator (long index, unsigned long in1, unsigned long in2, } r9 = arg.ret; status = arg.status; - xfree(e); + if (r9 >= 0) { + IA64_SAL_DEBUG("SAL_CLEAR_STATE_INFO: more errors are available\n"); + spin_lock_irqsave(&sal_queue_lock, flags); + list_add(&e->list, &sal_queue[in1]); + spin_unlock_irqrestore(&sal_queue_lock, flags); + } } break; case SAL_MC_RENDEZ: -- 2.30.2